package com.itheima.d6_jdk8_time;
import java.time.LocalTime;

public class Test2_LocalTime {
    public static void main(String[] args) {
        // 0、获取本地时间对象： 时 分 秒 纳秒 不可变的
        LocalTime now = LocalTime.now();

        // 1、获取时间中的信息
        //时
        System.out.println("now.getHour() = " + now.getHour());
        //分
        System.out.println("now.getMinute() = " + now.getMinute());
        //秒
        System.out.println("now.getSecond() = " + now.getSecond());
        //纳秒
        System.out.println("now.getNano() = " + now.getNano()); //now.getNano() = 429585000
        System.out.println("now.getNano() = " + now.getNano()); //now.getNano() = 429585000
        //相同的原因是，只是输出了2次，没有创建新的对象

        System.out.println(LocalTime.now().getNano()); //433233000
        System.out.println(LocalTime.now().getNano()); //433254000
        //不同的原因是，代码执行需要花费时间

        // 2、修改时间：withHour、withMinute、withSecond、withNano
        LocalTime time1 = now.withHour(18);
        System.out.println("time1 = " + time1);

        // 3、加多少：plusHours、plusMinutes、plusSeconds、plusNanos
        LocalTime time2 = now.plusHours(100);
        System.out.println("time2 = " + time2);

        // 4、减多少：minusHours、minusMinutes、minusSeconds、minusNanos
        LocalTime time3 = now.minusHours(1);
        System.out.println("time3 = " + time3);

        // 5、获取指定时间的LocalTime对象：
        // public static LocalTime of(int hour, int minute, int second)
        LocalTime time4 = LocalTime.of(18, 18, 18);
        System.out.println("time4 = " + time4);

        // 6、判断2个时间对象，是否相等，在前还是在后： equals isBefore isAfter
        LocalTime t1 = LocalTime.of(18, 0, 0);
        LocalTime t2 = LocalTime.of(18, 0, 0);
        LocalTime t3 = LocalTime.of(18, 10, 0);
        System.out.println("t1.equals(t2) = " + t1.equals(t2)); //true
        System.out.println("t2.isBefore(t3) = " + t2.isBefore(t3)); //true
        System.out.println("t3.isAfter(t2) = " + t3.isAfter(t2)); //true
    }
}
